<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/public/header.jsp"%>
<% 
	String callback = request.getParameter("callback");
	String xm_id=request.getParameter("xm_id")==null?"0":request.getParameter("xm_id");
%>
<html>
	<head>
		<title>工单集合选择</title>
	</head>
	<script type="text/javascript">
		$(function(){

			$("#searchValue").keypress(function(e) { 
		    	// 回车键事件 
		     	if(e.which == 13) { 
		     		 doSearch();
		       	} 
			});
			$("#dept_id").combotree({
				url:'<%=contextPath %>/springMVC/group/listDepartment',
				method:'POST',
				animate:true,
				lines:true,
				onChange:function(){
					doSearch();
				}
			});
			
			$('#table').datagrid({
				title:"工单池",
				iconCls:'icon-edit',
				loadMsg:'正在加载数据，请稍后......',
				url:'<%=contextPath %>/springMVC/xm/listGdByXmId?xm_id=<%=xm_id%>&flag=1',
				rownumbers:true,
				fitColumns:true,
				nowrap:false,
				idField:'id',
				frozenColumns:[[
					{field:'ck',checkbox:true},
				    {title:'工单id',field:'gd_id',hidden:true},
				    {title:'借款单id',field:'id',hidden:true}

				]],
				columns:[[
					{title:'所属部门',field:'dept_name',width:100,align:'center'},
					{title:'工单编号',field:'gd_code',width:100,align:'center'},
					{title:'工单名称',field:'gd_name',width:200,align:'center'},
					{title:'借款人',field:'person_name',width:100,align:'center'},
					{title:'日期',field:'operation_date',width:100,align:'center',sort:true},
					{title:'放款日期',field:'actual_operation_date',width:100,align:'center',sort:true},
					{title:'金额',field:'money',width:100,align:'center'},
					{title:'摘要',field:'remark',width:200,align:'center'},
					{title:'操作',field:'edit',width:100,align:'center',formatter:function(value,rowData,rowIndex){
	                	return "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-details' title='查看' onclick=\"javascript:addOrEditLoan('"+rowData.id+"');\"/>&nbsp;&nbsp;";

					}}
				]],
				pageSize:10,
				pageList : [10,50,100],  
				pagination:true,
				onLoadSuccess:function(rtJson){
					if(rtJson.rtState== '1')
					{
						$.messager.alert('提示',rtJson.rtMsrg);
					}
				}
			});
		});
		function addOrEditLoan(id){
			openDialogResize("<%=contextPath%>/springViews/gd/addOrEditLoan.jsp?isShow=1&id="+id,1000,800);
		}
       function doSubmit(){
    	  var rows=$('#table').datagrid('getSelections');
			var ids="";
			var gd_codes="";
			var gd_names="";
			var person_names="";
			var actual_operation_dates="";
			var moneys="";
			var sumMoneys="";
			for(var i=0;i<rows.length;i++)
			{
				if(i==(rows.length-1))
				{
					ids+=rows[i].id;
					gd_codes+=rows[i].gd_code;
					gd_names+=rows[i].gd_name;
					person_names+=rows[i].person_name;
					actual_operation_dates+=rows[i].actual_operation_date;
					moneys+=rows[i].money;
				}else
				{
					ids+=rows[i].id+",";
					gd_codes+=rows[i].gd_code+",";
					gd_names+=rows[i].gd_name+",";
					person_names+=rows[i].person_name+",";
					actual_operation_dates+=rows[i].actual_operation_date+",";
					moneys+=rows[i].money+",";
				}
				sumMoneys+=rows[i].money;
			}
			
			window.opener.addRows(ids,sumMoneys,gd_codes,gd_names,person_names,actual_operation_dates,moneys);
			window.close();
       }
   	function doSearch()
	{
		var dept_id = $('#dept_id').combotree('getValue');
		var searchValue = $('#searchValue').val();
		var start_time=$('#start_time').datebox('getValue');  
		var end_time=$('#end_time').datebox('getValue');  
		$('#table').datagrid('load',				
			{
				dept_id:dept_id,
				searchValue:searchValue,
				start_time:start_time,
				end_time:end_time
			}
		);
	}
</script>
<body style="height: 97%">
	<div id="table" data-options="fit:true,toolbar:'#tb'" ></div>
	<div id="tb" style="padding:3px;height:auto">
		<div style="float:left">
			<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-ok',plain:true" onclick="doSubmit();">确定</a>
		</div>
		<div align="right">
			 开始时间：<input id="start_time" name="start_time" class="easyui-datebox"  style="width:100px" />&nbsp;&nbsp;&nbsp;结束时间：<input id="end_time" name="end_time" class="easyui-datebox" style="width:100px" />
			选择部门：<input  id="dept_id" name="dept_id" class="easyui-combotree">  
			工单编号/名称：<input id="searchValue" name="searchValue" style="width:150px" title="工单编号/名称" placeholder="工单编号/名称"/>&nbsp;&nbsp;
			<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="doSearch();"></a>
		</div>
	</div>
	</body>
</html>